package com.example.nfcproducttracing;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.os.Bundle;

public class ProductTracer extends Activity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		

		FragmentManager fm = getFragmentManager();
		FragmentTransaction ft = fm.beginTransaction();
		
        StartFragment startFragment = new StartFragment();
		ft.replace(R.id.fragmentContainer, startFragment);
		ft.commit();
		
        this.onNewIntent(getIntent());
	}
	
    @Override
    protected void onResume()
    {
            super.onResume();
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState)
    {
    	super.onSaveInstanceState(outState);
    }
    
    @Override
    protected void onNewIntent(Intent intent)
    {
    	super.onNewIntent(intent);
		
		if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
		
	        if (intent.getType().equals("text/product"))
	        {
	    		startActivity(intent.setClass(ProductTracer.this, ProductActivity.class));
	        }
	        else if (intent.getType().equals("text/pesticide"))
	        {
	        	startActivity(intent.setClass(ProductTracer.this, PesticideActivity.class));
	        }
	        else if (intent.getType().equals("text/seed"))
	        {
	    		startActivity(intent.setClass(ProductTracer.this, SeedActivity.class));
	        }
		}
    }
}
